package com.loto.service.impl;

import com.loto.TDEmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

@Service
public class TDEmailServiceImpl implements TDEmailService {
    @Autowired(required = true)
    private JavaMailSender mailSender;

    @Value("${spring.mail.from}")
    private String from;

    /**
     * 发送验证码到邮箱，true成功，false失败
     */
    public boolean sendEmail(String email, String code) {
        //创建SimpleMailMessage对象
        SimpleMailMessage message = new SimpleMailMessage();

        //邮件发送人
        message.setFrom(from);
        //邮件接收人
        message.setTo(email.split(";"));
        //邮件主题
        message.setSubject("【TD】SpringCloudNetflix 登录注册短信验证码");
        //邮件内容
        message.setText("验证码：" + code);
        
        //发送邮件
        mailSender.send(message);
        return true;
    }
}
